<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		<meta http-equiv="Expires" content="0" />
		<title>卓越网络管理系统</title>
<link rel="stylesheet" type="text/css" href="${ctx}/js/ext-3.0.3/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/scripts/hxcy/hxcy-main.css" />
<script type="text/javascript" src="${ctx}/js/ext-3.0.3/adapter/ext/ext-base.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/js/ext-3.0.3/ext-all.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/js/ext-3.0.3/source/locale/ext-lang-zh_CN.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/js/ext-3.0.3/ux/ux-all.js" charset="UTF-8"></script> 
<script type="text/javascript" src="${ctx}/scripts/hxcy/hxcy-util.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/scripts/hxcy/hxcy-cmp.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/fgys/s/Message.js" charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/fgys/s/showMessage.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8"><!--
	
	/**
	 * 退出系统
	 */
	function logout() {
		Ext.Msg.confirm('确认', "确定要退出系统吗?", function (btn) {
			if (btn == "yes") {
				//window.location="${ctx}/account/logout!logout.action";
				window.location="<c:url value='/j_spring_security_logout'/>";
			}
		});
	}

	/**
	* 权限按钮集合
	*/
	var menuItems=[];
		/*[
	          	  {"id":"ts","title":"投诉管理","style":"TOUSU","url":"ts-main.jsp","menus":[]},
	          	  {"id":"gc","title":"工程管理","style":"GONGCHENG","url":"gc-main.jsp","menus":[
	          	  	  {"id":"gc-fgys","title":"覆盖延伸建设","menus":[
	                    {"id":"gc-fgys-xjxm","title":"新建项目","url":"/login.jsp","style":"veh-icon-7"}
	                    ]},                         	  
	          		  {"id":"gc-jz","title":"基站建设","menus":[
	          		  {"id":"gc-jz-xjxm","title":"新建项目","url":"/login.jsp","style":"veh-icon-7"}
	          		  ]},
	          		  {"id":"gc-yh","title":"优化建设","menus":[
	             		  {"id":"gc-yh-xjxm","title":"新建项目","url":"/login.jsp","style":"veh-icon-7"}
	             		]} 
	          	  ]},
	          	 {"id":"pc","title":"普查管理","style":"PUCHA","url":"pc-main.html","menus":[]},
	          	  {"id":"qyw","title":"全业务管理","style":"QUANYEWU","url":"qyw-main.html","menus":[]},
	          	  {"id":"wy","title":"物业管理","style":"WUYE","url":"wy.html","menus":[]}
	          	  ];
	          	 */
	/**
	 * 一级菜单的获取
	 */
	function getOneMenu(menuItems){
		var oneMenu='';
		if(menuItems.length>0){
			for(var i=menuItems.length-1;i>=0;i--){
				//图片文字未分离样式
				//oneMenu+='<a id="'+menuItems[i].id+'" class="'+menuItems[i].style+'" href="javascript:changeNav('+i+')"></a>';
				
				//图片文件分离样式
				oneMenu+='<span style="cursor: pointer;" onclick="javascript:changeNav(\''+i+'\')"><table cellpadding="0px" cellspacing="0px" border="0px" align="center"><tr><td><div class="'+menuItems[i].style+'1" onclick="this.className=\''+menuItems[i].style+'3\'" onmouseover="this.className=\''+menuItems[i].style+'2\'" onmouseout="this.className=\''+menuItems[i].style+'1\'"></div></td><tr/><tr ><td  class="Level1_Text">'+menuItems[i].title+'</td></tr></table></span>';
			}
		}else{
			oneMenu='';
		}
		return oneMenu;
	}
	
	/**
	 * 二项菜单集合（包含三项菜单）
	 * @type Json格式
	 * 格式说明:
	 * 二级菜单：
	 * 	[id:二级菜单ID,title:二级菜单名称,"menus":三级菜单集合]
	 * 三级菜单：
	 * [id:"三级菜单ID",title:"三级菜单名称",url:"三级菜单连接URL",style:"三级菜单样式class"]
	 * 注：url地址不需要加项目名直接连接地址
	 */
	/*var navItemsJson =[];
		[{"id":"nav1","title":"基站建设","menus":[
				{"id":"ps1","title":"基站建设1","url":"/login.jsp","style":"veh-icon-7"},
				{"id":"ps2","title":"基站建设2","url":"/index.jsp","style":"veh-icon-8"},
				{"id":"ps4","title":"基站建设4","url":"/index.jsp","style":"veh-icon-8"},
				{"id":"ps3","title":"基站建设3","url":"/login.jsp","style":"veh-icon-9"}]},
				
		{"id":"nav2","title":"室内分布","menus": [
			{"id":"pf1","title":"室内分布1","url":"/login.jsp","style":"veh-icon-5"},
			{"id":"pf2","title":"室内分布2","url":"/index.jsp","style":"veh-icon-6"}]},
			
		{"id":"nav3","title":"物业管理","menus": [
			{"id":"wy1","title":"物业管理1","url":"/login.jsp","style":"veh-icon-3"},
			{"id":"wy2","title":"物业管理2","url":"/index.jsp","style":"veh-icon-4"}]}];
	*/
	/**
	*根据一级菜单获取子集合
	*/
	function getTwoMenu(id){
		var navItemsJson=[];
		if(menuItems.length>0){
			for(var i=0;i<menuItems.length;i++){
			if(menuItems[i].id==id){
					navItemsJson=menuItems[1].menus.concat();//复制一个数组
					break;
				}
			}
		}
		return navItemsJson;
	}
	var exit = {
		id : 'exit',
		iconCls : 'veh-icon-30',
		text : '退出系统',
		handler : function() {
			Ext.Msg.confirm('确认', "<br />&nbsp;&nbsp;确认退出系统?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", function(btn) {
				if (btn == "yes") {// 确认提交
					window.location=Hxcy.CPT + '/public/exitMain.action';
				}
			});
		}
	}
	/**
	 * 创建IFrame窗口，IFrameid = "iframe" +  二级id 
	 * @param {} power 子项权限集合（三级权限）
	 * @return {} 返回构建的IFrame窗口
	 */
	function getIFrame(power){
		var iFrame = new Hxcy.IFrame({
			id :"iframe"+power.id,
			closable : true,
			title :power.title,
			xtype : 'iframe',
			url : Hxcy.CPT + power.url
		})
		return iFrame;
	}

	/**
	 * 创建三级菜单
	 * @param {} power 三级菜单集合
	 * @return {} 三级菜单
	 */
	function getNavItem(power){
		var hxcyBtn = new Hxcy.BoxButton({
			text:power.title,
			iconCls:power.style,
			listeners:{
				"click":function(){
					Hxcy.CmpMgr.showTab(getIFrame(power));//将iframe显示到右边TablePanel中
				}
			}
		});
		return hxcyBtn;
	}

	/**
	 * 将创建的三级菜单添加到二级菜单中
	 * @param {} nav 二级菜单对象
	 * @param {} powerJson 三级菜单集合 Json格式
	 */
	function getNavItems(nav,powerJson){
		for(var i = 0;i<powerJson.length;i++){
			nav.items.push(getNavItem(powerJson[i]));
		}
	}

	/**
	 * 创建二级菜单
	 * @return {} 创建的二级菜单
	 */
	function getNav(id){
		var navMenu = [];
		if(id < menuItems.length){
			var navItemsJson=menuItems[id].menus.concat();//默认加入第一个模块的二，三级菜单
			if(navItemsJson.length>0){
				for(var i=0;i<navItemsJson.length;i++){
					var nav={
						id :  navItemsJson[i].id,
						title : navItemsJson[i].title,
						defaults : {
							xtype : 'Hxcyboxbutton'
						},
						items : []
						
					};
					getNavItems(nav,navItemsJson[i].menus);
					navMenu.push(nav);
				}
			}
		}
		return navMenu;
	}

	changeMenus=function(id){
		Hxcy.main.Nav.navMenu=getNav(id);
		Hxcy.main.Panel.west.items=Hxcy.main.Nav.navMenu;
		debugger;
		window.location.reload();
	};
	/*
	 * 覆盖延伸布局面板(北，南，西，中，东)
	 */
	Hxcy.main.Panel = {
		north: {
			id: "toolBar",
			region : 'north',
			cls : 'banner-class banner-class-vhc',
			//html : '<div class="banner" style="float:right;margin:0px 5px;" id="toolBarDiv"></div>',
			margins : '5 5 5 5',
			height : 72,
			items : [

					]
		},
		south : {
			id : "statusBar",
			region : 'south',
			height : 25,
			margins : '5 5 5 5',
			items : {
				xtype : "statusbar",
				defaultText : "卓越网络工程管理系统",
				defaultIconCls : "x-status-default-icon",
				busyText : "正在加载数据...",
				items : ['<img src="${ctx}/scripts/hxcy/images/016.gif"></img>  管理员   [设置]  '+
				         '<a href="#" onclick="javascript:logout()" style="text-decoration:none;">[注销]</a>'
						]
			}
		},
		west : {
			id : 'nav',
			region : 'west',
			split : true,
			layout : 'accordion',
			cls : 'accordion-button',
			width : '15%',
			minSize : 110,
			maxSize : 200,
			margins : '0 0 0 5',
			layoutConfig : {
				animate : true
			},
			defaults : {
				border : false,
				iconCls : 'x-accordion-item',
				autoScroll : true
			},
			items : []
		},
		center : {
			id : 'contentWrapper',
			layoutOnTabChange : true,// 这个选项怎样形容重要都不会过
			xtype : 'hxcytabpanel',
			defaults : {
				border : false,
				bodyBorder : false
			},
			activeItem : 0,
			region : 'center',
			title : "内容列表",
			margins : "0 5 0 0",
			plugins : new Ext.ux.TabCloseMenu(),
			items : [{
				title: '工作台 ',
				closable: false,
				html:'<img border="0" width="100%" height="100%" src="${ctx}/scripts/hxcy/images/welcome.jpg"'+' />'
			}]
		}
	};

	
	function changeNav(id){
		Hxcy.main.Nav=function(){
			 var navMenu=getNav(id);
			 if(navMenu.length==0){
				navMenu.push({
					id : 'v-has-no-auth',
					title : '没有权限',
					defaults : {
						xtype : 'Hxcyboxbutton'
					},
					items : [exit]
				});
			}
			/* else {
				navMenu[navMenu.length-1].items.push(exit);
			}*/

			return {
				navMenu : navMenu
			}
		}();

		//alert(123123);
		var nav = Ext.getCmp('nav');
		
		nav.removeAll(true);	
			
		nav.add(Hxcy.main.Nav.navMenu);
		
		nav.doLayout();
		
	}
	
	Ext.onReady(function(){
		var viewport=new Ext.Viewport({
		layout:'border',
		id:'viewport',
		items: [
				Hxcy.main.Panel.north,
				Hxcy.main.Panel.south,
				Hxcy.main.Panel.west,
				Hxcy.main.Panel.center
			]
		});

		Ext.Ajax.request({
			url:Hxcy.CPT+"/account/menuJson.action",
			method:'GET',
			success:function(rs){
				var rst = Ext.decode(rs.responseText);
				menuItems = rst;

				//修改二三级菜单
				changeNav(0);
				
				//修改一级菜单
				var toolBar = Ext.getCmp("toolBar");
				var toolBarLabel = new Ext.form.Label({
					name : "toolBarLabel",
					html : '<div class="banner" style="float:right;margin:0px 5px;" >'+getOneMenu(menuItems)+'</div>'
				});
				toolBar.add(toolBarLabel);
				toolBar.doLayout();
			}
		});
	});
--></script>
</head>
<body>
<table cellpadding="0px" cellspacing="0px" border="0px"></table>
</body>
</html>